package com.crape.account.bo.impl;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.crape.account.bo.IAccountHelperBO;
import com.crape.common.bean.LoginUser;
import com.crape.common.model.AccountInfo;


public class AccountHelperBOImpl implements IAccountHelperBO {

    @Override
    public LoginUser setupAccountInfo(HttpServletRequest request, HttpServletResponse response, AccountInfo acct) {
        HttpSession session = request.getSession();
        LoginUser loginUser = new LoginUser();
        loginUser.setLoginId(acct.getUsername());
        loginUser.setPassword(acct.getPassword());
        // 设置用户session
        loginUser.setEmail(acct.getEmail());
        loginUser.setAccountid(acct.getAccountid());
        loginUser.setUsername(acct.getUsername());
        loginUser.setUsertype(acct.getUsertype());
        loginUser.setImagename(acct.getImagename());
        session.setAttribute(LoginUser.SESSION_LOGINUSER, loginUser);
        // 设置Cookie
        Cookie loginIdCookie = new Cookie("loginIdCookie", loginUser.getLoginId());
        Cookie passwordCookie = new Cookie("passwordCookie", loginUser.getPassword());
        response.addCookie(loginIdCookie);
        response.addCookie(passwordCookie);
        return loginUser;
    }

}
